package com.ruoyi.project.system.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.security.service.TokenService;
import com.ruoyi.project.system.domain.College;
import com.ruoyi.project.system.domain.Student;
import com.ruoyi.project.system.domain.StudentCourseQuestion;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.CollegeMapper;
import com.ruoyi.project.system.mapper.StudentCourseQuestionMapper;
import com.ruoyi.project.system.mapper.StudentMapper;
import com.ruoyi.project.system.service.IStudentCourseQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 学生课程练习Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-10-07
 */
@Service
public class StudentCourseQuestionServiceImpl implements IStudentCourseQuestionService
{
    @Autowired
    private StudentCourseQuestionMapper studentCourseQuestionMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private CollegeMapper collegeMapper;

    /**
     * 查询学生课程练习
     * 
     * @param id 学生课程练习ID
     * @return 学生课程练习
     */
    @Override
    public StudentCourseQuestion selectStudentCourseQuestionById(Integer id)
    {
        return studentCourseQuestionMapper.selectStudentCourseQuestionById(id);
    }

    /**
     * 查询学生课程练习列表
     * 
     * @param studentCourseQuestion 学生课程练习
     * @return 学生课程练习
     */
    @Override
    public List<StudentCourseQuestion> selectStudentCourseQuestionList(StudentCourseQuestion studentCourseQuestion)
    {
        return studentCourseQuestionMapper.selectStudentCourseQuestionList(studentCourseQuestion);
    }

    /**
     * 新增学生课程练习
     * 
     * @param studentCourseQuestion 学生课程练习
     * @return 结果
     */
    @Override
    public int insertStudentCourseQuestion(StudentCourseQuestion studentCourseQuestion)
    {

        Student student = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest()).getStudent();
        College college = collegeMapper.selectCollegeById(student.getCollegeId());
        studentCourseQuestion.setStudentName(student.getRealName());
        studentCourseQuestion.setCollegeCode(college.getCollegeCode());
        studentCourseQuestion.setCollegeId(college.getCollegeId());
        studentCourseQuestion.setCollegeName(college.getCollegeName());
        studentCourseQuestion.setSubmitDt(new Date());
        return studentCourseQuestionMapper.insertStudentCourseQuestion(studentCourseQuestion);
    }

    /**
     * 修改学生课程练习
     * 
     * @param studentCourseQuestion 学生课程练习
     * @return 结果
     */
    @Override
    public int updateStudentCourseQuestion(StudentCourseQuestion studentCourseQuestion)
    {
        return studentCourseQuestionMapper.updateStudentCourseQuestion(studentCourseQuestion);
    }

    /**
     * 批量删除学生课程练习
     * 
     * @param ids 需要删除的学生课程练习ID
     * @return 结果
     */
    @Override
    public int deleteStudentCourseQuestionByIds(Integer[] ids)
    {
        return studentCourseQuestionMapper.deleteStudentCourseQuestionByIds(ids);
    }

    /**
     * 删除学生课程练习信息
     * 
     * @param id 学生课程练习ID
     * @return 结果
     */
    @Override
    public int deleteStudentCourseQuestionById(Integer id)
    {
        return studentCourseQuestionMapper.deleteStudentCourseQuestionById(id);
    }
}
